package com.jwdf.uda.ui.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.view.View;

import com.jwdf.uda.R;
import com.jwdf.uda.databinding.ItemGuideInteractionTitleBinding;
import com.jwdf.uda.event.GuideDetailEvent;
import com.jwdf.uda.ui.adapter.AbsViewHolder;
import com.jwdf.uda.ui.adapter.item.GuideDetailItem;
import com.jwdf.uda.utils.DateUtils;
import com.jwdf.uda.utils.EventBusUtil;

/**
 * 类说明：
 */
public class GuideInteractionTitleViewHolder extends AbsViewHolder<GuideDetailItem> {
    private ItemGuideInteractionTitleBinding mItemBinding;

    public GuideInteractionTitleViewHolder(View convertView) {
        super(convertView);
        mItemBinding = DataBindingUtil.bind(convertView);
    }

    @Override
    protected void onBindView(final GuideDetailItem item) {
        mItemBinding.tvTitle.setText(getConvertView().getContext().getString(R.string.guide_detail_interaction_title, item.interactionCount > 0 ? String.valueOf(item.interactionCount) : ""));
        mItemBinding.tvSort.setText(item.sortType);
        mItemBinding.flDropMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.interactionCount > 0) {
                    GuideDetailEvent event = new GuideDetailEvent(GuideDetailEvent.EVENT_SHOW_DROP_MENU);
                    event.anchor = v;
                    EventBusUtil.post(event);
                }
            }
        });

        if(item.evaluationTime > 0){
            mItemBinding.tvDate.setVisibility(View.VISIBLE);
            String evaluation = "";
            switch (item.evaluation){
                case GUIDE_EVALUATION_NONE:
                    evaluation = getConvertView().getContext().getString(R.string.guide_detail_evaluation_none);
                    break;
                case GUIDE_EVALUATION_GOOD:
                    evaluation = getConvertView().getContext().getString(R.string.guide_detail_evaluation_good);
                    break;
                case GUIDE_EVALUATION_NORMAL:
                    evaluation = getConvertView().getContext().getString(R.string.guide_detail_evaluation_normal);
                    break;
                case GUIDE_EVALUATION_BAD:
                    evaluation = getConvertView().getContext().getString(R.string.guide_detail_evaluation_bad);
                    break;
            }
            mItemBinding.tvDate.setText(getConvertView().getContext().getString(R.string.guide_detail_interaction_evaluation, DateUtils.getFriendlyTime(item.evaluationTime), evaluation));
        }else{
            mItemBinding.tvDate.setVisibility(View.GONE);
        }
    }
}
